/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.backlog.dao.hibernate;

import br.com.backlog.dao.DAOFactory;
import br.com.backlog.dao.content_management.ProductDAO;
import br.com.backlog.dao.content_management.ProjectDAO;
import br.com.backlog.dao.content_management.ReportDAO;
import br.com.backlog.dao.content_management.SprintDAO;
import br.com.backlog.dao.content_management.TaskDAO;
import br.com.backlog.dao.content_management.UserDAO;
import br.com.backlog.dao.hibernate.content_management.ProductHibernateDAO;
import br.com.backlog.dao.hibernate.content_management.ProjectHibernateDAO;
import br.com.backlog.dao.hibernate.content_management.ReportHibernateDAO;
import br.com.backlog.dao.hibernate.content_management.SprintHibernateDAO;
import br.com.backlog.dao.hibernate.content_management.TaskHibernateDAO;
import br.com.backlog.dao.hibernate.content_management.UserHibernateDAO;
import org.hibernate.Session;

/**
 *
 * @author Gleibson Oliveira
 */
public class HibernateDAOFactory extends DAOFactory{


    @SuppressWarnings("unchecked")
    private GenericHibernateDAO instantiateDAO(Class daoClass) {
        try {
            GenericHibernateDAO dao = (GenericHibernateDAO)daoClass.newInstance();
            dao.setSession(getCurrentSession());
            return dao;
        } catch (Exception ex) {
            throw new RuntimeException("Can not instantiate DAO: " + daoClass, ex);
        }
    }
    protected Session getCurrentSession() {
        return HibernateUtil.getSessionFactory().getCurrentSession();
    }

    @Override
    public ProductDAO getProductDAO() {
        return (ProductDAO) instantiateDAO(ProductHibernateDAO.class);
    }

    @Override
    public ProjectDAO getProjectDAO() {
        return (ProjectDAO) instantiateDAO(ProjectHibernateDAO.class);
    }

    @Override
    public ReportDAO getReportDAO() {
        return (ReportDAO) instantiateDAO(ReportHibernateDAO.class);
    }

    @Override
    public SprintDAO getSprintDAO() {
        return (SprintDAO) instantiateDAO(SprintHibernateDAO.class);
    }

    @Override
    public TaskDAO getTaskDAO() {
        return (TaskDAO) instantiateDAO(TaskHibernateDAO.class);
    }

    @Override
    public UserDAO getUserDAO() {
        return (UserDAO) instantiateDAO(UserHibernateDAO.class);
    }

}
